package com.example.myapplication.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class ObjectDetectViewModel : ViewModel() {
    private var lastObjectId: String? = null
    private var lastTimestamp: Long = 0
    private val _objectDetected = MutableLiveData<String?>()
    val objectDetected: LiveData<String?> = _objectDetected

    fun onObjectDetected(id: String) {
        val now = System.currentTimeMillis()
        if (id == lastObjectId) {
            if (now - lastTimestamp >= 3000) {
                _objectDetected.postValue(id)
            }
        } else {
            lastObjectId = id
            lastTimestamp = now
        }
    }
} 